package com.itheima.controller;

import com.itheima.anno.LogOperation;
import com.itheima.domain.pojo.Dept;
import com.itheima.domain.vo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.OutputBuffer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:篍
 * @Date: 2025/07/10 10:10
 * @Description:Fighting TODO
 */
@RestController
@RequestMapping("/depts")
@Slf4j
public class DeptController {
    @Autowired
    DeptService deptService;
    @GetMapping
    public Result findAll(){
        /**
         * 查找所有部门并返回Result
         */
        log.info("查找所有部门并返回Result");
        List<Dept> depts = deptService.findAll();
        return Result.success(depts);
    }


    /**
     * 根据id删除部门
     */
    @DeleteMapping
    @LogOperation
    public Result deleteDeptById(Integer id){
        System.out.println(deptService.deleteDeptById(id));
        return Result.success();
    }
    @LogOperation
    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        System.out.println(deptService.addDept(dept));
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findOneDeptById(@PathVariable("id") Integer deptId){
        System.out.println("deptId = " + deptId);
        Dept dept=deptService.findOneDeptById(deptId);
        return Result.success(dept);
    }

    @LogOperation
    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        System.out.println("dept = " + dept);
        deptService.updateDept(dept);
        return Result.success();
    }




}
